<script type="text/javascript" language="javascript" src="<?= base_url() ?>public/js/jquery.validate.js"></script>
<script src="<?php echo base_url(); ?>public/js/chosen.jquery.min.js" type="text/javascript"></script>
<script src="<?php echo base_url(); ?>public/js/ajax-chosen.min.js" type="text/javascript"></script>
<!--<script src="<?php echo base_url(); ?>public/js/jquery/jquery.filestyle.js" type="text/javascript"></script>-->
<script src="<?php echo base_url(); ?>public/js/ajax.updatelocation.js" type="text/javascript"></script>
<script src="<?php echo base_url(); ?>public/js/validation-custom-text.js" type="text/javascript"></script>
<script type="text/javascript">
    
    // Declare official id and Datatable
    var official_order_ID  = 0,  official_medal_order_ID  = 0, isOfficialAdd = true, omoTable, omrTable; 
    
    $(document).ready(function(){
        
        // change official form to add (default: add/update)	
        changeOfficialForm(); 
        // Auto update province
        requestUpdateProvince($('#sprovince'));
        
        // Apply select to chosen format
                
        $("#sministry").chosen(); 
        $("#sprovince").chosen(); 
        $("#sdistrict").chosen(); 
        $("#scommune").chosen(); 
        $("#svillage").chosen(); 
        $("#sstatus").chosen(); 
        $("#ministry").chosen(); 
        $("#province").chosen(); 
        $("#district").chosen(); 
        $("#commune").chosen(); 
        $("#village").chosen(); 
        $("#status").chosen(); 
        $("#medaltype").chosen(); 
        $("#medalclass").chosen(); 
        
        // ajax chosen for officer
        $("#officialname").ajaxChosen({
            method: 'GET',
            url: '<?php echo base_url(); ?>index.php/officer/officer_list',
            dataType: 'json'
        }, function (data) {
            var terms = {};			
            $.each(data, function (i, val) {
                terms[val.ID] = val.name;
            });			
            return terms;
        });
        
        // ajax chosen for medal
        $("#medal").ajaxChosen({
            method: 'GET',
            url: '<?php echo base_url(); ?>index.php/medal_receipt/medal_list',
            dataType: 'json'
        }, function (data) {
            var terms = {};			
            $.each(data, function (i, val) {
                terms[val.ID] = val.full_name;
            });			
            return terms;
        }); 
        
        // ajax chosen for medal
        $("#medalofficer").ajaxChosen({
            method: 'GET',
            url: '<?php echo base_url(); ?>index.php/medal_receipt/medal_list',
            dataType: 'json'
        }, function (data) {
            var terms = {};			
            $.each(data, function (i, val) {
                terms[val.ID] = val.full_name;
            });			
            return terms;
        }); 
        
		
		
        //event handler for show more search form element
        $('#show-more').click(function (e){
            e.preventDefault();
            $('#search-detail').slideToggle("slow");
        });
		
        //Change to background color of each table row when selecting row
        //And add event handler to retrieve related data
        $(".bedatable tbody tr").click( function( e ) {
            oTable.$('tr.row_selected').removeClass('row_selected');
            $(this).addClass('row_selected');
            //do sth else
            if ($.isFunction(window.ajaxGetRelatedData)) {
                //execute it
                ajaxGetRelatedData($(this));
            }
        });
        
        // datepicker date range
        $( "#sfromdate" ).datepicker({
            onSelect: function(selected) {
                $( "#stodate" ).datepicker( "option", "minDate", selected);
                $("#sofficialno").keyup();
            }
        });
        $( "#stodate" ).datepicker({
            onSelect: function(selected) {
                $( "#sfromdate" ).datepicker( "option", "maxDate", selected);
                $("#sofficialno").keyup();
            }
        });
	
        // Declare datable for official order              
        var oTable = $('#official-order-list').dataTable( {
            "bSortClasses": false,
            "bPaginate": true,
            "bLengthChange": true,
            "bFilter": false,
            "bSort": true,
            "bInfo": false,
            "bAutoWidth": false,
            "aoColumns" : [
                { sWidth: '30px' },
                { sWidth: '100px' },
                { sWidth: '90px' },
                { sWidth: '230px' }
            ] ,
            "aoColumnDefs": [ 
                { "bSortable": false, "aTargets": [ 0, 4, 5, 6 ] }
            ],
            "aaSorting": [[ 2, "desc" ]],
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": "<?php echo base_url(); ?>index.php/official_order/search?" + $('#search-official-form').serialize(),
            "fnDrawCallback": function( oSettings ) {
                clearOfficialOrder();                
                official_order_ID = 0;  
                official_medal_order_ID = 0;
                omoTable.fnReloadAjax("<?php echo base_url(); ?>index.php/official_order/official_medal_order?official_order_ID=" + official_order_ID);
                omrTable.fnReloadAjax("<?php echo base_url(); ?>index.php/official_order/medal_reception?official_order_ID=" + official_order_ID);
            }
        } );

        // Declare datable for official medal order         	
        omoTable = $('#official-medal-order').dataTable( {
            "bSortClasses": false,
            "bPaginate": true,
            "bLengthChange": true,
            "bFilter": false,
            "bSort": true,
            "bInfo": false,
            "bAutoWidth": false,
            "aoColumns" : [
                { sWidth: '30px' },
                { sWidth: '210px' },
                { sWidth: '210px' },
                { sWidth: '70px' },
                { sWidth: '70px' }
            ] ,
            "aoColumnDefs": [ 
                { "bSortable": false, "aTargets": [ 0, 5 ] }
            ],
            "aaSorting": [[ 1, "asc" ]],
            "bProcessing": true,
            "bServerSide": true, 
            "fnDrawCallback": function( oSettings ) {
                clearOfficialMedal();     
                official_medal_order_ID = 0;
                $.post("<?php echo base_url(); ?>index.php/medal/Medal_list", "", function(callback){  
                    $("#medal").html(callback).trigger("liszt:updated");;
                });
            },
            "sAjaxSource": "<?php echo base_url(); ?>index.php/official_order/official_medal_order?official_order_ID=" + official_order_ID
        });	

        // Declare datable for officer reception         	
        omrTable = $('#official-model-order-list').dataTable( {
            "bSortClasses": false,
            "bPaginate": true,
            "bLengthChange": true,
            "bFilter": false,
            "bSort": true,
            "bInfo": false,
            "bAutoWidth": false,
            "aoColumns" : [
                { sWidth: '30px' },
                { sWidth: '100px' },
                { sWidth: '200px' },
                { sWidth: '220px' },
                { sWidth: '100px' }
            ] ,
            "aoColumnDefs": [ 
                { "bSortable": false, "aTargets": [ 0, 5 ] }
            ],
            "aaSorting": [[ 1, "asc" ]],
            "bProcessing": true,
            "bServerSide": true, 
            "fnDrawCallback": function( oSettings ) {
                clearMedalReceipt();     
            },
            "sAjaxSource": "<?php echo base_url(); ?>index.php/official_order/medal_reception?official_order_ID=" + official_order_ID
        });	
	
        //add event handler for search form elements
        $('#sofficialno, #sfromdate, #stodate', '#svillage', '#sministry', '#sstatus').change(function(){ oTable.fnReloadAjax(); });
		
        //------------------------------------------
		
        //add event handler for add form officeial order        
        $('#official-order-submit').click(function (e){
            e.preventDefault();
            $("#official-form").submit();
        });
        
        //add event handler for add form officeial amount      
        $('#official-amount-submit').click(function (e){
            e.preventDefault();
            $("#frm-medal-amount").submit();
        });
        
        //add event handler for edit form officeial order form
        $(".edit-official").live('click', function(event){
            event.preventDefault();
            $("#officialid").val($(this).attr("rel"));
            isOfficialAdd = false;
            changeOfficialForm();
            officialReadData();            
        });
        
        //add event handler for edit form officeial order form
        $(".delete-official").live('click', function(event){
            event.preventDefault();
            var id = $(this).attr("rel");
            if(confirm("តើពិតជាចង់លុបមែនរឺ?")){
                var url = "<?php echo base_url(); ?>index.php/official_order/delete_official_order";
                var data = "ID=" + id;
                $.post(url, data, function(callback){     
                    if (!callback.result){
                        $('#form-add-official .err-msg').html(callback.message);
                    }else{   
                        $('#form-add-official .err-msg').html(callback.message);         
                        oTable.fnReloadAjax("<?php echo base_url(); ?>index.php/official_order/search?" + $('#search-official-form').serialize());
                    }
                }, "json");
            }
        });
        
        //add event handler for delete form officeial medal order form
        $(".delete-official-medal").live('click', function(event){
            event.preventDefault();
            var id = $(this).attr("rel");
            if(confirm("តើពិតជាចង់លុបមែនរឺ?")){
                var url = "<?php echo base_url(); ?>index.php/official_order/delete_official_medal_order";
                var data = "ID=" + id;
                $.post(url, data, function(callback){     
                    if (!callback.result){
                        $('#form-add-medal .err-msg').html(callback.message);
                    }else{   
                        $('#form-add-medal .err-msg').html(callback.message);         
                        omoTable.fnReloadAjax("<?php echo base_url(); ?>index.php/official_order/official_medal_order?official_order_ID=" + official_order_ID);
                    }
                }, "json");
            }
        });
        
        //add event handler for delete form officeial medal reception form
        $(".delete-medal-reception").live('click', function(event){
            event.preventDefault();
            var id = $(this).attr("rel");
            if(confirm("តើពិតជាចង់លុបមែនរឺ?")){
                var url = "<?php echo base_url(); ?>index.php/official_order/delete_medal_reception";
                var data = "ID=" + id;
                $.post(url, data, function(callback){     
                    if (!callback.result){
                        $('#form-add-reception .err-msg').html(callback.message);
                    }else{   
                        $('#form-add-reception .err-msg').html(callback.message);         
                        omrTable.fnReloadAjax("<?php echo base_url(); ?>index.php/official_order/medal_reception?official_order_ID=" + official_order_ID);
                    }
                }, "json");
            }
        });
                
        // Update Official Query Search         
        $("#sprovince").change(function(){ 
            oTable.fnReloadAjax( "<?php echo base_url(); ?>index.php/official_order/search?" + $('#search-official-form').serialize()); 
            requestUpdateDistrict($("#sdistrict"), $("#scommune"), $("#svillage"), $(this).val());
        }); 
	
        $("#sdistrict").change(function() {
            oTable.fnReloadAjax( "<?php echo base_url(); ?>index.php/official_order/search?" + $('#search-official-form').serialize()); 
            requestUpdateCommune($("#scommune"), $("#svillage"), $(this).val());
        }); 
        $("#scommune").change(function(){
            oTable.fnReloadAjax( "<?php echo base_url(); ?>index.php/official_order/search?" + $('#search-official-form').serialize()); 
            requestUpdateVillage($("#svillage"), $(this).val());
        });
        $("#sministry, #sstatus").change(function(){
            oTable.fnReloadAjax( "<?php echo base_url(); ?>index.php/official_order/search?" + $('#search-official-form').serialize()); 
        });
        $("#sofficialno").keyup(function(){
            oTable.fnReloadAjax( "<?php echo base_url(); ?>index.php/official_order/search?" + $('#search-official-form').serialize()); 
        });
        
        // On submit officer order
        $("#official-form").ajaxForm({
            beforeSubmit: function(){
                // validation
                validateDefaultText('#official-form input');
                var validate =    $('#official-form').validate().form();
                if (validate == false){
                    returnDefaultText('#official-form input');
                    validate.error();
                    return validate; 
                }
                // waiting
                $('#form-add-official .loading').show();
                $('#form-add-official .add-button').addClass('disable-add-button');
                $('#form-add-official .update-button').addClass('disable-update-button');
                $('#form-add-official .add-button, #form-add-official .update-button').attr('disabled', 'disabled');
            },
            url: '<?php echo base_url(); ?>index.php/official_order/add_official_order',
            dataType: 'json',
            error: function(){
                // stop waiting display error
                $('#form-add-official .err-msg').html("ទិន្នន័យមិនអាចរក្សាទុកបានដោយបញ្ហាបច្ចេកទេស");                
                $('#form-add-official .loading').hide();
                $('#form-add-official .add-button').removeClass('disable-add-button');
                $('#form-add-official .update-button').removeClass('disable-update-button');
                $('#form-add-official .add-button, #form-add-official .update-button').removeAttr('disabled');
            },
            success: function (data){                
                if (!data.result){
                    // data invalid
                    $('#form-add-official .err-msg').html(data.message);
                }else{            
                    // reset data
                    oTable.fnDraw(false);
                    clearOfficialOrder();
                    changeOfficialForm();
                    $('#form-add-official .err-msg').html(data.message);
                }
                // stop waiting
                $('#form-add-official .loading').hide();
                $('#form-add-official .add-button').removeClass('disable-add-button');
                $('#form-add-official .update-button').removeClass('disable-update-button');
                $('#form-add-official .add-button, #form-add-official .update-button').removeAttr('disabled');
            }
        });
        
        
        // On submit officer amount
        $("#frm-medal-amount").ajaxForm({
            beforeSerialize: function(){              
                // set official order id before sending data
                $("#frm-medal-amount #official_order_ID").val(official_order_ID);  
            },
            beforeSubmit: function(){
                // not selected official order
                if(official_order_ID == 0){
                    alert("សូមជ្រើសរើសក្រឹតជាមុន");
                    return false;
                }
                // validate
                validateDefaultText('#frm-medal-amount input');
                var validate = $('#frm-medal-amount').validate().form() ;
                if (validate == false){
                    returnDefaultText('#frm-medal-amount input');
                    validate.error();
                    return false; 
                }            
                // show waiting
                $('#form-add-medal .loading').show();
                $('#frm-medal-amount .add-button').addClass('disable-add-button').attr('disabled', 'disabled');
            },
            url: '<?php echo base_url(); ?>index.php/official_order/add_official_medal_Order',
            dataType: 'json',
            error: function (){
                // stop waiting display error
                $('#frm-medal-amount .err-msg').html("ទិន្នន័យមិនអាចរក្សាទុកបានដោយបញ្ហាបច្ចេកទេស");                
                $('#form-add-medal .loading').hide();
                $('#frm-medal-amount .add-button').removeClass('disable-add-button').removeAttr('disabled');                
            },
            success: function (data){      
                if (!data.result){
                    // data invalid
                    $('#form-add-medal .err-msg').html(data.message);
                }else{            
                    // success reset data
                    $('#form-add-medal .err-msg').html(data.message);
                    omoTable.fnDraw(false);
                } 
                // stop waiting
                $('#form-add-medal .loading').hide();
                $('#frm-medal-amount .add-button').removeClass('disable-add-button').removeAttr('disabled');      
            }
        });
        
        // On submit officer reception
        $("#frm-new-receipt").ajaxForm({
            beforeSerialize: function(){               
                // set officer order id before sending data
                $("#frm-new-receipt #official_order_ID").val(official_order_ID);  
            },
            beforeSubmit: function(){
                // check weather selected official order
                if(official_order_ID == 0){
                    alert("Please select official order.")
                    return false;
                }
                // validate
                validateDefaultText('#frm-new-receipt input');
                var validate = $('#frm-new-receipt').validate().form();
                if (validate == false){
                    returnDefaultText('#frm-new-receipt input');
                    validate.error();
                    return validate; 
                }
                // waitng status
                $('#form-add-reception .loading').show();
                $('#frm-new-receipt .add-button').addClass('disable-add-button').attr('disabled', 'disabled');
            },
            url: '<?php echo base_url(); ?>index.php/official_order/add_medal_reception',
            dataType: 'json',
            error: function (){
                // stop waiting display error
                $('#frm-new-receipt .err-msg').html("ទិន្នន័យមិនអាចរក្សាទុកបានដោយបញ្ហាបច្ចេកទេស");                
                $('#form-add-reception .loading').hide();
                $('#frm-new-receipt .add-button').removeClass('disable-add-button').removeAttr('disabled');                
            },
            success: function (data){      
                if (!data.result){
                    // data invalid
                    $('#form-add-reception .err-msg').html(data.message);
                }else{       
                    // data success and reset form
                    $('#form-add-reception .err-msg').html(data.message);
                    omrTable.fnReloadAjax("<?php echo base_url(); ?>index.php/official_order/medal_reception?official_order_ID=" + official_order_ID);
                }
                // stop waiting
                $('#form-add-reception .loading').hide();
                $('#frm-new-receipt .add-button').removeClass('disable-add-button').removeAttr('disabled');                
            }
        });
        
        function fnGetSelected( oTableLocal )
        {
            var aReturn = new Array();
            var aTrs = oTableLocal.fnGetNodes();
	
            for ( var i=0 ; i<aTrs.length ; i++ )
            {
                if ( $(aTrs[i]).hasClass('row_selected') )
                {
                    aReturn.push( aTrs[i] );
                }
            }
            return aReturn;
        }
        
        // allow selected row official order
        $("#official-order-list tbody").click(function(event) {
            $(oTable.fnSettings().aoData).each(function (){
                $(this.nTr).removeClass('row_selected');
            });
            $(event.target.parentNode).addClass('row_selected');
            official_order_ID = $(event.target.parentNode).find(".edit-official").attr("rel");
            omoTable.fnReloadAjax("<?php echo base_url(); ?>index.php/official_order/official_medal_order?official_order_ID=" + official_order_ID);
            omrTable.fnReloadAjax("<?php echo base_url(); ?>index.php/official_order/medal_reception?official_order_ID=" + official_order_ID);
        });
        
        // cancel official order
        $("#official-order-cancel").click(function(event) {
            event.preventDefault();
            clearOfficialOrder();
            changeOfficialForm();
        });        
        
        //---------------------------------------------
        // option when view for url /2 
        // it mean that it will auto open query search on start up
        openOption();
        //---------------------------------------------
    });	
	
    function ajaxGetRelatedData(eTarget){
        alert('Work...!');
        //get the related data through ajax
        //Data of required number of medal
		
        //Data of official to recieve the medal
		
    }
    
    // when change operation type (add/update)
    function changeOfficialForm(){
        if(isOfficialAdd){
            $("#official-order-update, #official-order-cancel").hide();
            $("#official-order-submit").show();
        }else{
            $("#official-order-update, #official-order-cancel").show();
            $("#official-order-submit").hide();            
        }
    }

    //official order data
    function officialReadData(){
        var id = $("#officialid").val(); 
        $.ajax({
            url: "<?php echo base_url(); ?>index.php/official_order/read_official_Order",
            data : "id="+id,
            type: "POST",
            dataType: "json",
            success: function(result){
                $("#officialno").val(result.Order_Number);
                $("#officialdate").datepicker("setDate", new Date(result.date));
                $("#status").val(result.order_status);
                $("#ministry").val(result.Ministry_ID);
                $("#province").val(result.province_ID);
                $("#officialid").val(id);
                
                $("#district").load('/webits-msms/index.php/location/get_district?provid='+result.province_ID, function(){
                    $("#district").val(result.district_ID).trigger("liszt:updated");  
                    $("#commune").load('/webits-msms/index.php/location/get_commune?distid='+result.district_ID, function(){
                        $("#commune").val(result.commune_ID).trigger("liszt:updated");
                        $("#village").load('/webits-msms/index.php/location/get_village?commid='+result.commune_ID, function(){
                            $("#village").val(result.village_ID).trigger("liszt:updated");
                        });
                    }); 
                });
                
               
                $("#status, #ministry, #province").trigger("liszt:updated");
                $("#official-form div.error").remove();
                if($.trim(result.order_file)!=''){
                    $("#officialfilelink").html('<a href="<?php echo base_url(); ?>public/files/'+result.order_file+'" target="_blank"><img align="absmiddle" src="<?php echo base_url(); ?>public/images/forms/download.png" />ដោនឡូដ</a>');
                }
                setDataEntered($("#form-add-official")); 
           }               
        });
    }
   
    // clear official order
    function clearOfficialOrder(){
        isOfficialAdd = true;
        $("#official-form #officialno").val("លេខ");
        $("#official-form #officialdate").val("កាលបរិច្ឆេទ​");
        $("#official-form #officialfilelink, #form-add-official .err-msg").html(""); 
        $("#official-form #status, #official-form #officialfile, #official-form #ministry, #official-form #province, #official-form #district, #official-form #commune, #official-form #village, #official-form #officialid").val("");
        $("#official-form #status, #official-form #ministry, #official-form #province, #official-form #district, #official-form #commune, #official-form #village").trigger("liszt:updated");            

                
        $('#official-form .populated-text').each(function () {
            populateText($(this));
        }); 
    }
    
    // clear official medal order
    function clearOfficialMedal(){    
        $("#frm-medal-amount #amount").val("ចំនួន");    
        $("#frm-medal-amount #remain-amount").val("ចំនួនខ្វះ");    
        $("#frm-medal-amount select").val("").trigger("liszt:updated");
        $("#form-add-medal .err-msg").html("");              
        $('#frm-medal-amount .populated-text').each(function () {
            populateText($(this));
        }); 
    }
    
    // clear official reception
    function clearMedalReceipt(){          
        $("#form-add-reception .err-msg").html("");  
        $('#form-add-reception select').val("").trigger("liszt:updated");
        $('#form-add-reception #receptiondate').val("កាលបរិច្ឆេទ​");
        $('#frm-medal-amount .populated-text').each(function () {
            populateText($(this));
        }); 
    }
    
    function openOption(){
<?php
// option 2 it will auto open status តាមដាន
if ($option == '2') {
    ?>
                $('#search-detail').slideToggle("slow");   
                $("#sstatus").val(1).trigger("liszt:updated");
                $("#sofficialno").keyup();
    <?php
}
?>
    }
</script>

<div id="left-content">
    <div id="official-panel" class="content-block">
        <div class="block-header"><?php echo $title_official; ?></div>
        <div id="block-content">
            <div id="search-panel">
                <fieldset>
                    <legend>ស្វែងរក</legend>
                    <form id="search-official-form" method="get" autocomplete="off" name="search-official-form">
                        <input type="text" name="sofficialno" id="sofficialno" value="លេខ​" class="text input required populated-text" />
                        <input type="text" name="sfromdate" id="sfromdate" class="input text datepicker populated-text" value="ពីថ្ងៃទី​" />
                        <input type="text" name="stodate" id="stodate" class="input text datepicker populated-text" value="ដល់ថ្ងៃទី​" />
                        <input type="hidden" value="<?php echo $order_type; ?>" id="order_type" name="order_type" />
                        <span id="show-more"><a href="#">បញ្ជាក់បន្ថែម</a></span>
                        <div id="search-detail">
                            <select id="sministry" name="sministry" class="required"/>
                            <option value="" >សំរាប់ក្រសួង​</option>
                            <?php
                            foreach ($ministries as $ministry):
                                echo "<option value='{$ministry['ID']}'>{$ministry['name']}</option>";
                            endforeach;
                            ?>
                            </select>
                            <select id="sprovince" name="sprovince" class="required"/>
                            <option value="" >នៅខេត្ត/ទីក្រុង​</option>
                            </select>
                            <select id="sdistrict" name="sdistrict" class="required"/>
                            <option value="" >ស្រុក​</option>
                            </select>
                            <select id="scommune" name="scommune" class="required"/>
                            <option value="" >ឃុំ</option>
                            </select>
                            <select id="svillage" name="svillage" class="required"/>
                            <option value="" >ភូមិ</option>
                            </select>
                            <select id="sstatus" name="sstatus" class="required"/>
                            <option value="" >ស្ថានភាព</option><?php
                            foreach ($official_statuses as $official_status):
                                echo "<option value='{$official_status['ID']}'>{$official_status['name']}</option>";
                            endforeach;
                            ?>
                            </select>
                        </div>
                    </form>
                </fieldset>
            </div>
            <div id="official-list">
                <table id="official-order-list" class="no-vertical-border bedatable">
                    <thead>
                        <tr>
                            <th class="index-col">ល.រ</th>
                            <th>លេខក្រឹត្យ</th>
                            <th>កាលបរិច្ឆេទ</th>
                            <th>ក្រសួង</th>
                            <th align="center" class="blank-header" ></th>
                            <th align="center" class="blank-header" ></th>
                            <th align="center" class="blank-header" ></th>
                        </tr>
                    </thead>
                </table>
            </div>
            <div class="break"></div>
            <div class="form-add-panel" id="form-add-official">
                <div id="title">បញ្ជូលប័ណ្ណបន្ថែម៖</div>
                <div class="err-msg"></div>
                <div class="loading"><img src="<?php echo base_url(); ?>public/images/forms/loading-bar.gif" /></div>
                <form id="official-form" method="post" name="official-form" autocomplete="off" enctype="multipart/form-data">
                    <input type="text" name="officialno" id="officialno" value="លេខ​" class="text input required left populated-text" />
                    <input type="text" name="officialdate" id="officialdate" class="input text datepicker left populated-text required dateDefault" value="កាលបរិច្ឆេទ​" />
                    <select id="status" name="status" class="required"/>
                    <option value="" >ស្ថានភាព</option>
                    <?php
                    foreach ($official_statuses as $official_status):
                        echo "<option value='{$official_status['ID']}'>{$official_status['name']}</option>";
                    endforeach;
                    ?>
                    </select>
                    <select id="ministry" name="ministry" />
                    <option value="" >សំរាប់ក្រសួង​</option>
                    <?php
                    foreach ($ministries as $ministry):
                        echo "<option value='{$ministry['ID']}'>{$ministry['name']}</option>";
                    endforeach;
                    ?>
                    </select>
                    <select id="province" name="province" />
                    <option value="" >ខេត្ត/ក្រុង​</option>
                    </select>
                    <select id="district" name="district"/>
                    <option value="" >ស្រុក​</option>
                    </select>
                    <select id="commune" name="commune" />
                    <option value="" >ឃុំ</option>
                    </select>
                    <select id="village" name="village" />
                    <option value="" >ភូមិ</option>
                    </select>
                    <label for="officialfile" id="officialfilelabel">ភ្ជាប់ឯកសារ PDF</label>
                    <br /><span id="officialfilelink"></span>
                    <input type="file" name="officialfile" id="officialfile" />
                    <input type="hidden" value="<?php echo $order_type; ?>" name="order_type" />
                    <input type="hidden" id="officialid" name="officialid" />
                    <input type="submit" id="official-order-cancel" name="official-order-cancel" value="" class="cancel-button right" />
                    <input type="submit" id="official-order-update" name="official-order-update" value="" class="update-button right" />
                    <input type="submit" id="official-order-submit" name="official-order-submit" value="" class="add-button right" />
                </form>
            </div>
        </div>
    </div>
    <div id="official-medal-amount" class="content-block">
        <div class="block-header">ចំនួនមេដាយដែលត្រូវការ</div>
        <div id="block-content">
            <!-- medal information  -->
            <table id="official-medal-order"  class="no-vertical-border">
                <thead>
                    <tr>
                        <th class="index-col">ល.រ</th>
                        <th >ប្រភេទ</th>
                        <th >ថ្នាក់</th>
                        <th >ចំនួន</th>
                        <th >ចំនួនខ្វះ</th>
                        <th align="center" class="blank-header" ></th>
                    </tr>
                </thead>
            </table>
            <div class="break"></div>
            <div id="form-add-medal" class="form-add-panel">
                <div id="title">បញ្ជូលចំនួនមេដាយដែលត្រូវការ៖</div>
                <div class="err-msg"></div>
                <div class="loading"><img src="<?php echo base_url(); ?>public/images/forms/loading-bar.gif" /></div>
                <form method="post" action="#" name='frm-medal-amount' autocomplete="off" id="frm-medal-amount" >
                    <select id="medal" name="medal" class="required"/>
                    <option value="" >ប្រភេទ (ថ្នាក់មេដាយ​)</option>                  
                    <?php
                    foreach ($medals as $medal):
                        echo "<option value='{$medal['ID']}'>{$medal['name']}</option>";
                    endforeach;
                    ?>
                    </select>

                    <input type="submit" id="official-amount-submit" value="" class="add-button right" />
                    <input type="text" id="amount" name="amount" class="integer text input required populated-text" value="ចំនួន" />
                    <input type="text" name="remain-amount" id="remain-amount" class="integer text input populated-text" value="ចំនួនខ្វះ"/>
                    <input type="hidden" id="official_order_ID" name="official_order_ID" />
                    <div class="break"></div>
                </form>
            </div>
        </div></div>
    <div id="official-receipt" class="content-block">
        <div class="block-header">មន្រ្តីទទួលមេដាយ</div>
        <div id="block-content">
            <!-- reception information  -->
            <table id="official-model-order-list"  class="no-vertical-border">
                <thead>
                    <tr>
                        <th class="index-col">លរ</th>
                        <th >ឋានៈ</th>
                        <th >ឈ្មោះ</th>
                        <th >ប្រភេទ/ថ្នាក់មេដាយ</th>
                        <th >កាលបរិច្ឆេទ</th>
                        <th align="center" class="blank-header" ></th>
                    </tr>
                </thead>
            </table>
            <div class="break"></div>
            <div class="form-add-panel" id="form-add-reception" >
                <div id="title">បញ្ជូលមន្រ្តីទទួលមេដាយ៖</div>
                <div class="err-msg"></div>
                <div class="loading"><img src="<?php echo base_url(); ?>public/images/forms/loading-bar.gif" /></div>
                <form method="post" action="#" name='frm-new-receipt' id="frm-new-receipt" >
                    <select id="officialname" name="officialname" class="required"/>
                    <option value="" >ឈ្មោះ​</option>           
                    <?php
                    foreach ($officers as $officer):
                        echo "<option value='{$officer['ID']}'>{$officer['name']}</option>";
                    endforeach;
                    ?>
                    </select>
                    <select id="medalofficer" name="medalofficer" class="required"/>
                    <option value="" >ប្រភេទ (ថ្នាក់មេដាយ​)</option>                  
                    <?php
                    foreach ($medals as $medal):
                        echo "<option value='{$medal['ID']}'>{$medal['name']}</option>";
                    endforeach;
                    ?>
                    </select>
                    <input type="text" name="receptiondate" id="receptiondate" class="input text datepicker left populated-text required dateDefault" value="កាលបរិច្ឆេទ​" />
                    <input type="hidden" id="official_order_ID" name="official_order_ID" />
                    <input type="submit" id="official-receipt-submit" value="" class="add-button right" />
                    <div class="break"></div>
                </form>
            </div>
        </div>
    </div>
</div>
<!--<div id="related-activity" class="content-block right">
        <div class="block-header">ប្រតិបត្តិសំខាន់ៗ</div>
    <div id="block-content"></div>
</div>-->